home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1468 / calc.frm < prev    next >
Text File  |  1996-07-19  |  11KB  |  363 lines

  1. VERSION 4.00
  2. Begin VB.Form Calculator 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Calculator"
  5.    ClientHeight    =   2520
  6.    ClientLeft      =   6555
  7.    ClientTop       =   345
  8.    ClientWidth     =   2655
  9.    ClipControls    =   0   'False
  10.    BeginProperty Font 
  11.       name            =   "System"
  12.       charset         =   0
  13.       weight          =   700
  14.       size            =   9.75
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    Height          =   2925
  20.    Icon            =   "calc.frx":0000
  21.    Left            =   6495
  22.    LinkMode        =   1  'Source
  23.    LinkTopic       =   "Form1"
  24.    LockControls    =   -1  'True
  25.    MaxButton       =   0   'False
  26.    ScaleHeight     =   2520
  27.    ScaleWidth      =   2655
  28.    Top             =   0
  29.    Width           =   2775
  30.    Begin VB.PictureBox picReadout 
  31.       Height          =   375
  32.       Left            =   120
  33.       ScaleHeight     =   315
  34.       ScaleWidth      =   2400
  35.       TabIndex        =   19
  36.       Top             =   105
  37.       Width           =   2460
  38.    End
  39.    Begin VB.CommandButton Number 
  40.       Caption         =   "7"
  41.       Height          =   420
  42.       Index           =   7
  43.       Left            =   120
  44.       TabIndex        =   7
  45.       Top             =   600
  46.       Width           =   420
  47.    End
  48.    Begin VB.CommandButton Number 
  49.       Caption         =   "8"
  50.       Height          =   420
  51.       Index           =   8
  52.       Left            =   600
  53.       TabIndex        =   8
  54.       Top             =   600
  55.       Width           =   420
  56.    End
  57.    Begin VB.CommandButton Number 
  58.       Caption         =   "9"
  59.       Height          =   420
  60.       Index           =   9
  61.       Left            =   1080
  62.       TabIndex        =   9
  63.       Top             =   600
  64.       Width           =   420
  65.    End
  66.    Begin VB.CommandButton Cancel 
  67.       Caption         =   "C"
  68.       Height          =   420
  69.       Left            =   1680
  70.       TabIndex        =   10
  71.       Top             =   600
  72.       Width           =   420
  73.    End
  74.    Begin VB.CommandButton CancelEntry 
  75.       Caption         =   "CE"
  76.       Height          =   420
  77.       Left            =   2160
  78.       TabIndex        =   11
  79.       Top             =   600
  80.       Width           =   420
  81.    End
  82.    Begin VB.CommandButton Number 
  83.       Caption         =   "4"
  84.       Height          =   420
  85.       Index           =   4
  86.       Left            =   120
  87.       TabIndex        =   4
  88.       Top             =   1080
  89.       Width           =   420
  90.    End
  91.    Begin VB.CommandButton Number 
  92.       Caption         =   "5"
  93.       Height          =   420
  94.       Index           =   5
  95.       Left            =   600
  96.       TabIndex        =   5
  97.       Top             =   1080
  98.       Width           =   420
  99.    End
  100.    Begin VB.CommandButton Number 
  101.       Caption         =   "6"
  102.       Height          =   420
  103.       Index           =   6
  104.       Left            =   1080
  105.       TabIndex        =   6
  106.       Top             =   1080
  107.       Width           =   420
  108.    End
  109.    Begin VB.CommandButton Operator 
  110.       Caption         =   "+"
  111.       Height          =   420
  112.       Index           =   1
  113.       Left            =   1680
  114.       TabIndex        =   12
  115.       Top             =   1080
  116.       Width           =   420
  117.    End
  118.    Begin VB.CommandButton Operator 
  119.       Caption         =   "-"
  120.       Height          =   420
  121.       Index           =   3
  122.       Left            =   2160
  123.       TabIndex        =   13
  124.       Top             =   1080
  125.       Width           =   420
  126.    End
  127.    Begin VB.CommandButton Number 
  128.       Caption         =   "1"
  129.       Height          =   420
  130.       Index           =   1
  131.       Left            =   120
  132.       TabIndex        =   1
  133.       Top             =   1560
  134.       Width           =   420
  135.    End
  136.    Begin VB.CommandButton Number 
  137.       Caption         =   "2"
  138.       Height          =   420
  139.       Index           =   2
  140.       Left            =   600
  141.       TabIndex        =   2
  142.       Top             =   1560
  143.       Width           =   420
  144.    End
  145.    Begin VB.CommandButton Number 
  146.       Caption         =   "3"
  147.       Height          =   420
  148.       Index           =   3
  149.       Left            =   1080
  150.       TabIndex        =   3
  151.       Top             =   1560
  152.       Width           =   420
  153.    End
  154.    Begin VB.CommandButton Operator 
  155.       Caption         =   "X"
  156.       Height          =   420
  157.       Index           =   2
  158.       Left            =   1680
  159.       TabIndex        =   14
  160.       Top             =   1560
  161.       Width           =   420
  162.    End
  163.    Begin VB.CommandButton Operator 
  164.       Caption         =   "/"
  165.       Height          =   420
  166.       Index           =   0
  167.       Left            =   2160
  168.       TabIndex        =   15
  169.       Top             =   1560
  170.       Width           =   420
  171.    End
  172.    Begin VB.CommandButton Number 
  173.       Caption         =   "0"
  174.       Height          =   420
  175.       Index           =   0
  176.       Left            =   120
  177.       TabIndex        =   0
  178.       Top             =   2040
  179.       Width           =   900
  180.    End
  181.    Begin VB.CommandButton Decimal 
  182.       Caption         =   "."
  183.       Height          =   420
  184.       Left            =   1080
  185.       TabIndex        =   18
  186.       Top             =   2040
  187.       Width           =   420
  188.    End
  189.    Begin VB.CommandButton Operator 
  190.       Caption         =   "="
  191.       Height          =   420
  192.       Index           =   4
  193.       Left            =   1680
  194.       TabIndex        =   16
  195.       Top             =   2040
  196.       Width           =   420
  197.    End
  198.    Begin VB.CommandButton Percent 
  199.       Caption         =   "%"
  200.       Height          =   420
  201.       Left            =   2160
  202.       TabIndex        =   17
  203.       Top             =   2040
  204.       Width           =   420
  205.    End
  206. End
  207. Attribute VB_Name = "Calculator"
  208. Attribute VB_Creatable = False
  209. Attribute VB_Exposed = False
  210. ' Sample program that comes with VB.
  211. ' Adapted for VBMaxLCD.dll by Mike Stanley
  212.  
  213.  
  214. ' ------------------------------------------------------------------------
  215. '               Copyright (C) 1994 Microsoft Corporation
  216. '
  217. ' You have a royalty-free right to use, modify, reproduce and distribute
  218. ' the Sample Application Files (and/or any modified version) in any way
  219. ' you find useful, provided that you agree that Microsoft has no warranty,
  220. ' obligations or liability for any Sample Application Files.
  221. ' ------------------------------------------------------------------------
  222. Option Explicit
  223. Dim Readout As New CLCD
  224.  
  225. Dim Op1, Op2                ' Previously input operand.
  226. Dim DecimalFlag As Integer  ' Decimal point present yet?
  227. Dim NumOps As Integer       ' Number of operands.
  228. Dim LastInput               ' Indicate type of last keypress event.
  229. Dim OpFlag                  ' Indicate pending operation.
  230. Dim TempReadout
  231.  
  232. ' Click event procedure for C (cancel) key.
  233. ' Reset the display and initializes variables.
  234. Private Sub Cancel_Click()
  235.     Readout.Caption = Format(0, "0.")
  236.     Op1 = 0
  237.     Op2 = 0
  238.     Form_Load
  239. End Sub
  240.  
  241. ' Click event procedure for CE (cancel entry) key.
  242. Private Sub CancelEntry_Click()
  243.     Readout.Caption = Format(0, "0.")
  244.     DecimalFlag = False
  245.     LastInput = "CE"
  246. End Sub
  247.  
  248. ' Click event procedure for decimal point (.) key.
  249. ' If last keypress was an operator, initialize
  250. ' readout to "0." Otherwise, append a decimal
  251. ' point to the display.
  252. Private Sub Decimal_Click()
  253.     If LastInput = "NEG" Then
  254.         Readout.Caption = Format(0, "-0.")
  255.     ElseIf LastInput <> "NUMS" Then
  256.         Readout.Caption = Format(0, "0.")
  257.     End If
  258.     DecimalFlag = True
  259.     LastInput = "NUMS"
  260. End Sub
  261.  
  262. ' Initialization routine for the form.
  263. ' Set all variables to initial values.
  264. Private Sub Form_Load()
  265.     DecimalFlag = False
  266.     NumOps = 0
  267.     LastInput = "NONE"
  268.     OpFlag = " "
  269.      
  270.     With Readout
  271.         .BackColor = &H808080
  272.         .ForeColor = &H0&
  273.         Set .Container = picReadout
  274.         .Caption = Format(0, "0.")
  275.     End With
  276.     
  277.     Decimal.Caption = Format(0, ".")
  278. End Sub
  279.  
  280. Private Sub Form_Unload(Cancel As Integer)
  281.     Set Readout = Nothing
  282.     Set Calculator = Nothing
  283. End Sub
  284.  
  285. ' Click event procedure for number keys (0-9).
  286. ' Append new number to the number in the display.
  287. Private Sub Number_Click(Index As Integer)
  288.     If LastInput <> "NUMS" Then
  289.         Readout.Caption = Format(0, ".")
  290.         DecimalFlag = False
  291.     End If
  292.     If DecimalFlag Then
  293.         Readout.Caption = Readout.Caption + Number(Index).Caption
  294.     Else
  295.         Readout.Caption = Left(Readout.Caption, InStr(Readout.Caption, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")
  296.     End If
  297.     If LastInput = "NEG" Then Readout.Caption = "-" & Readout.Caption
  298.     LastInput = "NUMS"
  299. End Sub
  300.  
  301. ' Click event procedure for operator keys (+, -, x, /, =).
  302. ' If the immediately preceeding keypress was part of a
  303. ' number, increments NumOps. If one operand is present,
  304. ' set Op1. If two are present, set Op1 equal to the
  305. ' result of the operation on Op1 and the current
  306. ' input string, and display the result.
  307. Private Sub Operator_Click(Index As Integer)
  308.     TempReadout = Readout.Caption
  309.     If LastInput = "NUMS" Then
  310.         NumOps = NumOps + 1
  311.     End If
  312.     Select Case NumOps
  313.         Case 0
  314.         If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
  315.             Readout.Caption = "-" & Readout.Caption
  316.             LastInput = "NEG"
  317.         End If
  318.         Case 1
  319.         Op1 = Readout.Caption
  320.         If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
  321.             Readout.Caption = "-"
  322.             LastInput = "NEG"
  323.         End If
  324.         Case 2
  325.         Op2 = TempReadout
  326.         Select Case OpFlag
  327.             Case "+"
  328.                 Op1 = CDbl(Op1) + CDbl(Op2)
  329.             Case "-"
  330.                 Op1 = CDbl(Op1) - CDbl(Op2)
  331.             Case "X"
  332.                 Op1 = CDbl(Op1) * CDbl(Op2)
  333.             Case "/"
  334.                 If Op2 = 0 Then
  335.                    MsgBox "Can't divide by zero", 48, "Calculator"
  336.                 Else
  337.                    Op1 = CDbl(Op1) / CDbl(Op2)
  338.                 End If
  339.             Case "="
  340.                 Op1 = CDbl(Op2)
  341.             Case "%"
  342.                 Op1 = CDbl(Op1) * CDbl(Op2)
  343.             End Select
  344.         Readout.Caption = Op1
  345.         NumOps = 1
  346.     End Select
  347.     If LastInput <> "NEG" Then
  348.         LastInput = "OPS"
  349.         OpFlag = Operator(Index).Caption
  350.     End If
  351. End Sub
  352.  
  353. ' Click event procedure for percent key (%).
  354. ' Compute and display a percentage of the first operand.
  355. Private Sub Percent_Click()
  356.     Readout.Caption = Readout.Caption / 100
  357.     LastInput = "Ops"
  358.     OpFlag = "%"
  359.     NumOps = NumOps + 1
  360.     DecimalFlag = True
  361. End Sub
  362.  
  363.